﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PropAndIndexersExample
{
    class Program
    {
        static void Main(string[] args)
        {

            MyArray array = new MyArray(3);
            Console.WriteLine(array[2]);

        }
    }

    class MyArray
    {
        private int[] innerArray;
        private int lenght;



        public MyArray(int arrayLenght)
        {
            Lenght = arrayLenght;
            innerArray = new int[Lenght];
            for (int i = 0; i < Lenght; i++)
            {
                innerArray[i] = i;
            }
        }

        public int Lenght
        {
            get { return lenght; }
            set { lenght = value; }
        }

        public int AiExample { get; set; }

        public int this[int index]
        {
            get { return innerArray[index]; }
            set
            {
                if (value < 0)
                {
                    innerArray[index] = 0;
                }
                else
                { 
                    innerArray[index] = value;
                }
            }
        }

        public int GetIndex(int index)
        {
            return innerArray[index];
        }

        public void SetIndex(int index, int value)
        {
            innerArray[index] = value;
        }


    }
}
